new Vue({
  components: {},
  el: '#product',
  data: {
    nowData: [],
    beforeData: [],
    nextData: {},
    nextTitle: '',
    disabledbefore: false,
    disablednext: false,
    beforeid: 0, //上一页的id
    nextid: 0, //下一页的id
    id: 0, //该页的id
  },
  mounted() {
    this.nowData = {}
    var that = this;
    this.id = get('id');
    //获取当前id的数据和下一条数据
    axios.get('http://dl.sword.ink:2334/project/' + this.id).then((res) => {
      that.nowData = JSON.parse(JSON.stringify(res.data.data[0]));
      //获取上两条数据
      axios
        .get('http://dl.sword.ink:2334/projectc/' + this.id + '&-1')
        .then((re) => {
          //如果当前数据之前没有数据了，那么设置上一条的按钮为不可用
          if (re.data.data.length < 1) {
            this.disabledbefore = true;
          }
          //将上条数据的id存到beforeid中
          this.beforeid = re.data.data[0].id;
        });
      axios
        .get('http://dl.sword.ink:2334/projectc/' + this.id + '&1')
        .then((r) => {
          //如果当前数据之前没有数据了，那么设置上一条的按钮为不可用
          if (r.data.data.length == 0) {
            that.nextTitle = "没有了";
            that.disablednext = true;
          } else {
            that.nextTitle = "下一篇";
            this.nextid = r.data.data[0].id;
          }
        });
    });

  },
  methods: {
    toBeforeNew() {
      this.nowData = {}
      document.location.href = './product.html?id=' + this.beforeid;
    },
    toNextNew() {
      this.nowData = {}
      document.location.href = './product.html?id=' + this.nextid;
    },
  },
});
//   获取id
function get(par) {
  //获取bai当前URL
  var local_url = window.location.href;

  //截取get字符串
  var getstr = local_url.substr(local_url.indexOf('?') + 1);

  //解析du成get数组
  var get = getstr.split('&');

  //查找要找的参数（zhipar）
  for (var i in get) {
    if (get[i].indexOf(par + '=') >= 0) {
      return get[i].replace(par + '=', '');
    }
  }
  //如果找不到返回daofalse
  return false;
}
